package com.bosssoft.setp.model.business.shop;

import com.bosssoft.setp.handler.TrainingPlaceProxy;
import com.bosssoft.setp.model.business.aliance.AlianceBusiness;
import com.bosssoft.setp.model.business.aliance.AlianceBusinessArea;
import lombok.Getter;
import lombok.Setter;
import xyz.erupt.annotation.Erupt;
import xyz.erupt.annotation.EruptField;
import xyz.erupt.annotation.sub_field.Edit;
import xyz.erupt.annotation.sub_field.EditType;
import xyz.erupt.annotation.sub_field.Readonly;
import xyz.erupt.annotation.sub_field.View;
import xyz.erupt.annotation.sub_field.sub_edit.ReferenceTableType;
import xyz.erupt.annotation.sub_field.sub_edit.ReferenceTreeType;
import xyz.erupt.annotation.sub_field.sub_edit.Search;
import xyz.erupt.upms.model.base.HyperModel;

import javax.persistence.*;

/**
 * 培训场所实体的类定义
 *
 * @author lin-gaoying
 * @version 1.0
 * @since 1.0
 */
@Erupt(name = "培训场所", dataProxy = TrainingPlaceProxy.class)
@Table(name = "setp_training_place")
@Entity
@Getter
@Setter
public class TrainingPlace extends HyperModel {

    @ManyToOne
    @JoinColumn(name = "aliance_business_id")
    @EruptField(
            views = {
                    @View(title = "加盟商名称", column = "name")
            },
            edit = @Edit(title = "加盟商名称", type = EditType.REFERENCE_TABLE,
                    referenceTableType = @ReferenceTableType(id = "id", label = "name")
                    , notNull = true, search = @Search(vague = true)
            )
    )
    private AlianceBusiness alianceBusiness;

    @EruptField(
            views = @View(title = "名称", sortable = true),
            edit = @Edit(title = "名称", notNull = true, search = @Search(vague = true))
    )
    private String name;

    @EruptField(
            edit = @Edit(title = "编号", readonly = @Readonly(add = true, edit = true))
    )
    private String number;

    @ManyToOne
    @JoinColumn(name = "tree_id")
    @EruptField(
            edit = @Edit(
                    title = "区域",
                    type = EditType.REFERENCE_TREE,
                    referenceTreeType = @ReferenceTreeType(
                            id = "id", label = "name",
                            pid = "parent.id"
                    )
            )
    )
    private AlianceBusinessArea area;

    @EruptField(
            views = @View(title = "地址"),
            edit = @Edit(title = "地址", notNull = true)
    )
    private String address;

    @EruptField(
            views = @View(title = "负责人"),
            edit = @Edit(title = "负责人", notNull = true)
    )
    private String principal;

    @EruptField(
            views = @View(title = "电话"),
            edit = @Edit(title = "电话", notNull = true)
    )
    private String phoneNumber;

    @EruptField(
            views = @View(title = "邮箱"),
            edit = @Edit(title = "邮箱", notNull = true)
    )
    private String mailbox;

    @ManyToOne
    @JoinColumn(name = "training_place_id")
    @EruptField(
            edit = @Edit(title = "父门店名称(若无则忽略)", type = EditType.REFERENCE_TABLE
                    , referenceTableType = @ReferenceTableType(dependField = "alianceBusiness",
                            dependColumn = "alianceBusiness.id")
            )
    )
    private TrainingPlace trainingPlace = null;

    @EruptField()
    private Long parentId;

    @EruptField(
            views = @View(title = "类型", sortable = true),
            edit = @Edit(title = "类型", notNull = true)
    )
    private String type;

}
